package org.hhf.ai.tools.funcalling;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Slf4j
@Configuration
public class FunctionConfig {
    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 自动注册所有tool类
     * @return
     */
    @Bean
    public FunctionRegistry functionRegistry() {
        FunctionRegistry registry = FunctionRegistry.getInstance();
        Map<String, FunctionTool> functionBeans = applicationContext.getBeansOfType(FunctionTool.class);
        // 扫描所有实现，注册所有函数
        for (Map.Entry<String, FunctionTool> entry : functionBeans.entrySet()) {
            String functionName = entry.getKey();
            FunctionTool function = entry.getValue();
            registry.registerFunction(functionName, function);
        }
        return registry;
    }
}
